#ifndef ENGINE_HPP_INCLUDED
#define ENGINE_HPP_INCLUDED

#include <vector>
#include <map>
#include <sstream>

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#include "game_state.hpp"
#include "player.hpp"

template<typename T> std::string val2str(T val) {
	std::stringstream ss;
	ss << val;
	return ss.str();
}

struct ScoreString {
	ScoreString(sf::String string): string(string), time(1.f) {
		
	}
	
	sf::String string;
	float time;
};

class GameState;

class Engine {
	public:
		// state management
		bool init(int width, int height, int bpp, std::string title, int aa);
		void cleanup();
		inline bool isRunning() { return running; }
		inline void quit() { running = false; }
		
		void changeState(GameState *state);
		void pushState(GameState *state);
		void popState();
		
		// main loop elements
		void handleEvents();
		void update();
		void draw();
		
		// resources management
		sf::Image& getImage(std::string filename);
		sf::SoundBuffer& getSound(std::string filename);
		sf::Font& getFont(std::string filename);
		void clearResources();
		
		// players
		std::map<int, Player> players;
		//std::queue<PlayerEvent> playerEvents;
		bool getPlayerEvent(PlayerEvent& playerEvent);
		
		sf::RenderWindow window;
	private:
		bool running;
		std::vector<GameState *> states;
		
		std::map<std::string, sf::Image> images;
		std::map<std::string, sf::SoundBuffer> sounds;
		std::map<std::string, sf::Font> fonts;
};

#endif // ENGINE_HPP_INCLUDED
